package info.nixbear.tgcms.admin.client.place;

import info.nixbear.tgcms.admin.shared.request.TemplateProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class TemplatesPlace extends Place {
	
	public static class TemplateEditPlace extends TemplatesPlace {
		String token;
		TemplateProxy template;
		
		public TemplateEditPlace(String token, TemplateProxy template) {
			this.token = token;
			this.template = template;
		}

		public String getToken() {
			return token;
		}
		
		public TemplateProxy getTemplate() {
			return template;
		}

		public static final String newToken = "new";
		
		public boolean isTokenANewToken() {
			return newToken.equals(token);
		}
	}
	
	@Prefix("templates")
	public static class Tokenizer implements PlaceTokenizer<TemplatesPlace> {

		@Override
		public TemplatesPlace getPlace(String token) {
			return (token==null || token.isEmpty())?new TemplatesPlace():new TemplateEditPlace(token, null);
		}

		@Override
		public String getToken(TemplatesPlace place) {
			return (place instanceof TemplateEditPlace)?((TemplateEditPlace) place).getToken():"";
		}
		
	}

}
